﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.UI;
using LMHTX.Modules.DIRECTORY.TEAM.Components;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using ASPNETVN.PORTAL.Components.Share;


namespace LMHTX.Modules.DIRECTORY.TEAM.Controls
{
    public partial class TeamManager : AddEditItemControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            //bind gridview
            DataSet ds = Components.Team.SelectAll_AreaName(this.ModuleID);
            gvTeam.DataSource = ds;
            gvTeam.DataBind();
            ViewState["dsTeam"] = ds;
        }

        protected void gvTeam_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                Response.Redirect(HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, Convert.ToInt32(e.CommandArgument), "AddEditItem"));
            }
        }

        protected void gvTeam_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                Components.Team.DeleteTeam(Convert.ToInt32(gvTeam.DataKeys[e.RowIndex].Value));
                DataSet ds = Components.Team.SelectAll_AreaName(this.ModuleID);
                gvTeam.DataSource = ds;
                gvTeam.DataBind();
                ViewState["dsTeam"] = ds;
            }
            catch { }
        }

        protected void gvTeam_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvTeam.PageIndex = e.NewPageIndex;
            //bind gridview
            if ((DataSet)ViewState["dsTeam"] != null)
            {
                gvTeam.DataSource = (DataSet)ViewState["dsTeam"];
                gvTeam.DataBind();
            }
            else
                LoadData();
        }
    }
}